package com.alan.crpx;

/**
 * 直接插入排序
 */
public class Zjcrpx {
    public static void main(String[] args) {
        int[] arr = {49,38,65,97,76,13,27,49,78,34,12,64,1};
        System.out.println("排序前：");
        for (int i=0;i<arr.length;i++){
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        //
        for (int i = 1; i < arr.length; i++){
            int temp = arr[i];
            int j;
            for (j = i-1; j >= 0; j--){
                if (arr[j] > temp){
                    arr[j+1] = arr[j];
                }else {
                    break;
                }
            }
            arr[j+1] = temp;
        }

        System.out.println("排序后：");
        for (int i=0;i<arr.length;i++){
            System.out.print(arr[i] + " ");
        }
    }
}
